package com.hyperchain.controller;

import cn.dev33.satoken.stp.StpUtil;

import com.hyperchain.entity.DbAccount;
import com.hyperchain.service.AuthService;
import com.hyperchain.util.ResultData;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Validated
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private  AuthService authService;


    @GetMapping("/hello")
    private String test(){
        return "hello1";
    }

    @PostMapping("/login")
    public ResultData<String> login(@RequestBody DbAccount account){
        return ResultData.success(authService.login(account));
    }

    @PostMapping("/logout")
    public ResultData<String> logout(){
        StpUtil.logout();
        return ResultData.success("成功登出");
    }

    @PostMapping("/register")
    public ResultData<Integer> register(@RequestBody DbAccount account){
        return ResultData.success(authService.register(account));
    }
}
